//
//  XBLaunchView.m
//  fangli
//
//  Created by Ethan on 14-4-1.
//  Copyright (c) 2014年 ethan. All rights reserved.
//

#import "XBLaunchView.h"
#import "UIView+Category.h"

//要展示的图片个数
static CGFloat const kCount = 3.0;

@interface XBLaunchView()

@property (nonatomic, retain) UIScrollView *scrollView;

@end

@implementation XBLaunchView

//- (void)dealloc {
//    self.scrollView = nil;
//    self.completeBlock = nil;
//    
//}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.scrollView = [[UIScrollView alloc] initWithFrame:frame];
        self.scrollView.bounces = NO;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.showsVerticalScrollIndicator = NO;
        self.scrollView.pagingEnabled = YES;
        for (int i = 0; i < kCount; ++i) {
            
            NSString *string = [NSString stringWithFormat:@"guide_%d%@", i+1, ([UIScreen mainScreen].bounds.size.height == 568 ? @"_568h" : @"")];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:string]];
            imageView.frame = self.bounds;
            imageView.left = i*imageView.width;
            [self.scrollView addSubview:imageView];
            if (i == kCount - 1) {
                imageView.userInteractionEnabled = YES;
                UITapGestureRecognizer *t = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
                [imageView addGestureRecognizer:t];
            }
        }
        self.scrollView.contentSize = CGSizeMake(self.width * kCount, self.height);
        
        [self addSubview:self.scrollView];
        
        
        
    }
    return self;
}

- (void)tap:(UITapGestureRecognizer*)gesture {
    if (self.completeBlock) {
        self.completeBlock();
    }
    [self.viewcontroller dismissViewControllerAnimated:YES completion:^{
    }];
//    [UIView animateWithDuration:0.2f animations:^{
//        self.alpha = 0.0f;
//        
//    } completion:^(BOOL finished) {
//        [self removeFromSuperview];
//    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
